var config = require('../../../utils/config');
var API_URL = config.API_URL;
var util = require('../../../utils/util');
Page({
    data: {
        showPW: 'password',
        showRE: 'password',
        focusPW: false,
        focusRE: false,
        password: true,
        newPassword:true,
    },
    onLoad: function () {

    },
    // 修改登陆密码的显示
    changePassword: function () {
        var showPW = this.data.showPW;
        showPW = showPW == 'text' ? 'password' : 'text';
        var focusPW = true;
        var password = !this.data.password;
        this.setData({
            showPW: showPW,
            focusPW: focusPW,
            password: password
        })
    },
    changeRe: function () {
        var showRE = this.data.showRE;
        showRE = showRE == 'text' ? 'password' : 'text';
        var focusRE = true;
        var newPassword = !this.data.newPassword;
        this.setData({
            showRE: showRE,
            focusRE: focusRE,
            newPassword: newPassword
        })
    },
    edit: function (e) {
        var that = this;
        console.log(e);
        var oldPassword = e.detail.value.oldPassword;
        var password = e.detail.value.password;
        var confirmPassword = e.detail.value.confirmPassword;
        if (oldPassword == "") {
            util.showNotice('请输入原密码');
            return
        }
        if (password == "") {
            util.showNotice('请输入新密码');
            return
        }
        if (confirmPassword == "") {
            util.showNotice('请再次输入新密码');
            return
        }
        if (password != confirmPassword) {
            util.showNotice('两次输入的密码不一样');
            return
        }
        let params = {
            old_password: oldPassword,
            new_password: password
        }
        util.PRL(API_URL.updata_password, params)
            .then(res => {
                if (res.data.status == 200) {
                    my.showToast({
                        content: '修改成功',
                        duration: 800,
                        mask: true
                    })
                    setTimeout(() => {
                        my.navigateBack({
                            delta: 1,
                        })
                    }, 800)
                } else {
                    util.showNotice(res.data.msg)
                }
            }).catch(res => {
                console.log(res);
            })
    }
})